function render_preview() {
    document.getElementById('preview').innerHTML = 
        new commonmark.HtmlRenderer().render(new commonmark.Parser().parse(editor.getValue()));
}

var editor_type = document.getElementById("editor_script").getAttribute("data-type");
var editor_mode = null;

switch (editor_type) {
    case 'article':   editor_mode = 'markdown'; break;
    case 'query':     editor_mode = 'application/sparql-query'; break;
    case 'template':  editor_mode = {name: 'jinja2', htmlMode: true}; break;
    case 'topic':     editor_mode = 'turtle'; break;
}

var editor = CodeMirror.fromTextArea(
    document.getElementById('content'),
    {
        mode: editor_mode,
        theme: 'default',
        lineNumbers: true,
        lineWrapping: true,
        scrollbarStyle: null,
        autofocus: false,
        spellcheck: false,
        autocapitalize: false,
        readOnly: true
    });

// Render initial document
render_preview();
    
